import type { ISchema } from "@formily/vue";
import type { Student } from "@/types/user";
import modifySchema from "@/utils/modifySchema";

/** 学生基础信息(base) */
export function StudentBase() {
  return {
    studentIdCard: {
      type: "string",
      title: "身份证号",
      "x-component": "Input",
      "x-decorator": "FormItem",
      "x-validator": "idcard",
    },
    studentName: {
      type: "string",
      title: "姓名",
      "x-component": "Input",
      "x-decorator": "FormItem",
    },
    birthday: {
      type: "string",
      title: "出生年月",
      "x-component": "DatePicker",
      "x-component-props": {
        type: "month",
      },
      "x-decorator": "FormItem",
    },
    studentNation: {
      type: "string",
      title: "民族",
      "x-component-props": {
        clearable: true,
        filterable: true,
      },
      "x-component": "Select",
      "x-decorator": "FormItem",
    },
    studentPolitical: {
      type: "string",
      title: "政治面貌",
      "x-component": "Select",
      "x-decorator": "FormItem",
    },
    province: {
      type: "string",
      title: "省份",
      "x-component": "Select",
      "x-component-props": {
        clearable: true,
        filterable: true,
      },
      "x-decorator": "FormItem",
    },
    phonenumber: {
      type: "string",
      title: "联系电话",
      "x-component": "Input",
      "x-decorator": "FormItem",
      "x-validator": "phone",
    },
    sex: {
      type: "string",
      title: "性别",
      "x-component": "Radio.Group",
      "x-decorator": "FormItem",
    },
    // heath: {
    //   'type': 'string',
    //   'title': '健康状况',
    //   'x-component': 'Radio.Group',
    //   'x-decorator': 'FormItem',
    // },
    nativePlace: {
      type: "string",
      title: "籍贯",
      "x-component": "Input.TextArea",
      "x-component-props": {
        placeholder:
          "填自己的出生地，具体到县/县级市/市辖区，如贵州省纳雍县/贵州省兴仁市/贵州省贵阳市花溪区",
      },
      "x-decorator": "FormItem",
    },
    studentFrom: {
      type: "string",
      title: "生源地",
      "x-component": "Input.TextArea",
      "x-component-props": {
        placeholder:
          "填报名高考的地方，填写格式参照籍贯，如贵州省纳雍县/贵州省兴仁市/贵州省贵阳市花溪区",
      },
      "x-decorator": "FormItem",
    },
    studentAddress: {
      type: "string",
      title: "家庭地址",
      "x-component": "Input.TextArea",
      "x-component-props": {
        placeholder: "身份证/户口簿上的地址",
      },
      "x-decorator": "FormItem",
    },
    nowAddress: {
      type: "string",
      title: "现居住地地址",
      "x-component": "Input.TextArea",
      "x-component-props": {
        placeholder: "家庭实际在住的详细地址（请不要填写大学地址）",
      },
      "x-decorator": "FormItem",
    },
    qq: {
      type: "string",
      title: "QQ号",
      "x-component": "Input",
      "x-decorator": "FormItem",
      "x-validator": "qq",
    },
    parentTel1: {
      type: "string",
      title: "家长联系方式 1",
      "x-component": "Input",
      "x-decorator": "FormItem",
      "x-validator": "phone",
    },
    parentTel2: {
      type: "string",
      title: "家长联系方式 2",
      "x-component": "Input",
      "x-decorator": "FormItem",
      "x-validator": "phone",
    },
    blankCode: {
      type: "string",
      title: "联名卡卡号",
      "x-component": "Input.TextArea",
      "x-decorator": "FormItem",
      "x-component-props": {
        placeholder:
          "没有办理就不填，这是兴业银行和人文科技学院联名卡,用于学校发放勤工助学金与奖学金",
      },
      "x-validator": `{{
        (input) => {
          let sum = 0
          let arr = (input + '').split('').reverse();
          for (let i = 0; i < arr.length; i++) {
              let digit = parseInt(arr[i]);
              if (i % 2 !== 0) {
                  digit *= 2;
              }
              if (digit > 9) {
                  digit -= 9;
              }
              sum += digit;
          }
          return ((sum % 10 === 0)) ? '' : '银行卡号不正确'
        }
      }}`,
    },
    hobbies: {
      type: "string",
      title: "特长或爱好",
      "x-component": "Input.TextArea",
      "x-decorator": "FormItem",
    },
    heath: {
      type: "string",
      title: "健康状况",
      "x-component": "Input",
      "x-decorator": "FormItem",
    },
    studentExamCode: {
      type: "string",
      title: "考生号",
      "x-component": "Input",
      "x-decorator": "FormItem",
    },
    graduationType: {
      type: "string",
      title: "毕业类型",
      "x-component": "Select",
      "x-decorator": "FormItem",
    },
    disciplines: {
      type: "string",
      title: "考生科类",
      "x-component": "Select",
      "x-component-props": {
        placeholder:
          "如文史、理工、体育文、体育理、艺术文、艺术理、（新高考省份：物理、历史）",
      },
      "x-decorator": "FormItem",
    },
    foreignLanguage: {
      type: "string",
      title: "外语语种",
      "x-component": "Select",
      "x-decorator": "FormItem",
    },
    communistYouthLeague: {
      type: "string",
      title: "何年何月在何地加入中国共青团",
      "x-component": "Input.TextArea",
      "x-component-props": {
        placeholder: "如2016年12月在XX中学加入中国共产主义青年团，没有则填“无”",
      },
      "x-decorator": "FormItem",
    },
    partyChina: {
      type: "string",
      title: "何年何月在何地加入中国共产党",
      "x-component": "Input.TextArea",
      "x-component-props": {
        placeholder: "如2019年12月在XX中学加入中国共产党，没有则填“无”",
      },
      "x-decorator": "FormItem",
    },
    studentOrganization: {
      type: "string",
      title: "何年何月在何地参加学生组织及任职情况",
      "x-component-props": {
        placeholder:
          "格式同上，大一新生填写高中经历；预科生填预科阶段的经历；专升本填专科经历，没有则填“无”",
      },
      "x-component": "Input.TextArea",
      "x-decorator": "FormItem",
    },
    rewardsPunishment: {
      type: "string",
      title: "何年何月在何地受到何种奖励或处分",
      "x-component": "Input.TextArea",
      "x-component-props": {
        placeholder:
          "格式同参加学生组织及任职情况填写格式一样，填写高中；预科阶段；专升本的获奖或处分情况，没有则填“无”",
      },
      "x-decorator": "FormItem",
    },
    dormitory: {
      type: "string",
      title: "宿舍号",
      "x-component": "Input",
      "x-component-props": {
        placeholder: "输入范例：1-607",
      },
      "x-decorator": "FormItem",
    },
    counsellor: {
      type: "string",
      title: "班主任",
      "x-component": "Input",
      "x-decorator": "FormItem",
    },
    counsellorTel: {
      type: "string",
      title: "班主任手机号码",
      "x-component": "Input",
      "x-decorator": "FormItem",
    },
    trainSection: {
      type: "string",
      title: "乘车购票区间",
      "x-component": "Input.TextArea",
      "x-component-props": {
        placeholder:
          "输入范例：凯里南    贵阳的可以填 无   注意：凯里南站，去掉“站”字。    此处只有从贵阳通过火车和高铁两种交通工具回家的同学能填，家住贵阳市内不填；无法乘坐火车和高铁两种工具到家的也不填",
      },
      "x-decorator": "FormItem",
    },
  };
}

/** 学生学校信息(base) */
export function StudentSchool() {
  return {
    studentCode: {
      type: "string",
      title: "学号",
      "x-component": "Input",
      "x-decorator": "FormItem",
    },
    studentCollege: {
      type: "string",
      title: "学院",
      "x-component": "Select",
      "x-decorator": "FormItem",
    },
    studentGrade: {
      type: "string",
      title: "年级",
      "x-component": "Select",
      "x-component-props": {
        placeholder: "请先选择学院信息",
      },
      "x-decorator": "FormItem",
    },
    studentMajor: {
      type: "string",
      title: "专业",
      "x-component": "Select",
      "x-component-props": {
        placeholder: "请先选择年级信息",
      },
      "x-decorator": "FormItem",
    },
    studentClass: {
      type: "string",
      title: "班级",
      "x-component-props": {
        placeholder: "请先选择专业信息",
      },
      "x-component": "Select",
      "x-decorator": "FormItem",
    },
    educationalYear: {
      type: "number",
      title: "学制",
      "x-component": "Input",
      "x-validator": "number",
      "x-decorator": "FormItem",
    },

    // directional: {
    //   'type': 'string',
    //   'title': '培养方式',
    //   'x-component': 'Input',
    //   'x-decorator': 'FormItem',
    // },
    admissionMethod: {
      type: "string",
      title: "入学方式",
      "x-component": "Select",
      "x-decorator": "FormItem",
    },
    // educationalLevel: {
    //   'type': 'string',
    //   'title': '学历层次',
    //   'x-component': 'Input',
    //   'x-decorator': 'FormItem',
    // },
    positionHeld: {
      type: "string",
      title: "所任职务",
      "x-component": "Input",
      "x-decorator": "FormItem",
    },
    tenureDuration: {
      type: "string",
      title: "任职时间",
      "x-component": "Input",
      "x-decorator": "FormItem",
    },
    overallAssessmentScore: {
      type: "string",
      title: "综合测评成绩",
      "x-component": "Input",
      "x-decorator": "FormItem",
    },
    classRank: {
      type: "string",
      title: "班级排名",
      "x-component": "Input",
      "x-decorator": "FormItem",
    },
    classSize: {
      type: "string",
      title: "班级人数",
      "x-component": "Input",
      "x-decorator": "FormItem",
    },
    averageGPA: {
      type: "string",
      title: "平均学分绩点",
      "x-component": "Input",
      "x-decorator": "FormItem",
    },
    retakeExamCount: {
      type: "string",
      title: "重修补考次数",
      "x-component": "Input",
      "x-decorator": "FormItem",
    },
    rewardAcquisitionDate: {
      type: "string",
      title: "何时获得奖励何时获得奖励",
      "x-component": "Input.TextArea",
      "x-decorator": "FormItem",
    },
    keyAchievements: {
      type: "string",
      title: "主要事迹",
      "x-component": "Input.TextArea",
      "x-decorator": "FormItem",
    },
  };
}

/** 学生教育信息(base) */
export function StudentScore() {
  return {
    submissionScore: {
      type: "number",
      title: "投档成绩（总分）",
      "x-component": "Input",
      "x-decorator": "FormItem",
      "x-validator": "number",
      minimum: 0,
      maximum: 750,
    },
    chinese: {
      type: "number",
      title: "语文",
      "x-component": "Input",
      "x-decorator": "FormItem",
      minimum: 0,
      maximum: 150,
    },
    math: {
      type: "number",
      title: "数学",
      "x-component": "Input",
      "x-decorator": "FormItem",
      minimum: 0,
      maximum: 150,
    },
    language: {
      type: "number",
      title: "外语",
      "x-component": "Input",
      "x-decorator": "FormItem",
      minimum: 0,
      maximum: 150,
    },
    physics: {
      type: "number",
      title: "物理",
      "x-component": "Input",
      "x-decorator": "FormItem",
      minimum: 0,
      maximum: 150,
    },
    chemistry: {
      type: "number",
      title: "化学",
      "x-component": "Input",
      "x-decorator": "FormItem",
      minimum: 0,
      maximum: 150,
    },
    biology: {
      type: "number",
      title: "生物",
      "x-component": "Input",
      "x-decorator": "FormItem",
      minimum: 0,
      maximum: 150,
    },
    politics: {
      type: "number",
      title: "政治",
      "x-component": "Input",
      "x-decorator": "FormItem",
      minimum: 0,
      maximum: 150,
    },
    history: {
      type: "number",
      title: "历史",
      "x-component": "Input",
      "x-decorator": "FormItem",
      minimum: 0,
      maximum: 150,
    },
    geography: {
      type: "number",
      title: "地理",
      "x-component": "Input",
      "x-decorator": "FormItem",
      minimum: 0,
      maximum: 150,
    },

    comprehensive: {
      type: "number",
      title: "综合",
      "x-component": "Input",
      "x-decorator": "FormItem",
      "x-component-props": {
        placeholder: "若无综合分数请填一个'无'字，不加双引号",
      },
      minimum: 0,
      maximum: 300,
    },
    // 注意:featureScore=各项分数的总和（包括政策加分）
    featureScore: {
      type: "number",
      title: "总分",
      "x-component": "Input",
      "x-decorator": "FormItem",
    },
    // culturalScore: {
    //   'type': 'number',
    //   'title': '文化成绩（艺体）',
    //   'x-component': 'Input',
    //   'x-decorator': 'FormItem',
    //   'minimum': 0,
    //   'maximum': 150,
    // },
    majorScore: {
      type: "number",
      title: "专业成绩（艺体）",
      "x-component": "Input",
      "x-decorator": "FormItem",
      minimum: 0,
      maximum: 150,
    },
    policyPoints: {
      type: "number",
      title: "政策加分",
      "x-component": "Input",
      "x-decorator": "FormItem",
      minimum: 0,
      maximum: 150,
    },
    professionalNum: {
      type: "string",
      title: "专业录取志愿",
      "x-component": "Input",
      "x-decorator": "FormItem",
    },
  };
}

export function StudentExtraInfo() {
  return {
    familyMembers: {
      type: "array",
      "x-component": "ArrayTable",
      "x-decorator": "FormItem",
      title: "家庭主要成员及主要社会关系情况",
      items: {
        type: "object",
        properties: {
          c1: {
            type: "void",
            "x-component": "ArrayTable.Column",
            "x-component-props": {
              width: 80,
              title: "#",
              align: "center",
            },
            properties: {
              index: {
                type: "void",
                "x-component": "ArrayTable.Index",
              },
            },
          },
          c2: {
            type: "void",
            "x-component": "ArrayTable.Column",
            "x-component-props": {
              width: 200,
              title: "关系",
              align: "center",
            },
            properties: {
              relationship: {
                type: "string",
                "x-component": "Input.TextArea",
                required: true,
                "x-decorator": "FormItem",
                "x-component-props": {
                  placeholder:
                    "父子/父女、母子/母女、兄弟、兄妹、姐弟、姐妹、祖孙等",
                },
              },
            },
          },
          c3: {
            type: "void",
            "x-component": "ArrayTable.Column",
            "x-component-props": {
              width: 120,
              title: "姓名",
              align: "center",
            },
            properties: {
              name: {
                type: "string",
                "x-component": "Input",
                required: true,
                "x-decorator": "FormItem",
              },
            },
          },
          c4: {
            type: "void",
            "x-component": "ArrayTable.Column",
            "x-component-props": {
              width: 150,
              title: "民族",
              align: "center",
            },
            properties: {
              nation: {
                type: "string",
                "x-component-props": {
                  clearable: true,
                  filterable: true,
                },
                "x-component": "Select",
                required: true,
                "x-decorator": "FormItem",
              },
            },
          },
          c5: {
            type: "void",
            "x-component": "ArrayTable.Column",
            "x-component-props": {
              width: 150,
              title: "政治面貌",
              align: "center",
            },
            properties: {
              political: {
                type: "string",
                "x-component": "Select",
                required: true,
                "x-decorator": "FormItem",
              },
            },
          },
          c6: {
            type: "void",
            "x-component": "ArrayTable.Column",
            "x-component-props": {
              title: "工作单位及职务",
              align: "center",
            },
            properties: {
              unitAndPosition: {
                type: "string",
                "x-component": "Input.TextArea",
                required: true,
                "x-decorator": "FormItem",
                "x-component-props": {
                  placeholder:
                    "有固定工作的填写工作单位名称及职务；有固定工作已退休的填写原工作单位名称（退休）；在家务农的填写在家务农即可；在外打工的填写在某省务工，如在广东省务工",
                },
              },
            },
          },
          c7: {
            type: "void",
            "x-component": "ArrayTable.Column",
            "x-component-props": {
              width: 200,
              title: "联系电话",
              align: "center",
            },
            properties: {
              tel: {
                type: "string",
                "x-component": "Input",
                required: true,
                "x-decorator": "FormItem",
              },
            },
          },
          c8: {
            type: "void",
            "x-component": "ArrayTable.Column",
            "x-component-props": {
              title: "操作",
              prop: "operations",
              width: 200,
            },
            properties: {
              item: {
                type: "void",
                "x-component": "FormItem",
                properties: {
                  remove: {
                    type: "void",
                    "x-component": "ArrayTable.Remove",
                  },
                  moveDown: {
                    type: "void",
                    "x-component": "ArrayTable.MoveDown",
                  },
                  moveUp: {
                    type: "void",
                    "x-component": "ArrayTable.MoveUp",
                  },
                },
              },
            },
          },
        },
      },
      properties: {
        add: {
          type: "void",
          "x-component": "ArrayTable.Addition",
          title: "添加条目",
        },
      },
    },
    educationalExperience: {
      type: "array",
      "x-component": "ArrayTable",
      "x-decorator": "FormItem",
      title: "学习经历（从小学入学填起）",
      items: {
        type: "object",
        properties: {
          c1: {
            type: "void",
            "x-component": "ArrayTable.Column",
            "x-component-props": {
              width: 80,
              title: "#",
              align: "center",
            },
            properties: {
              index: {
                type: "void",
                "x-component": "ArrayTable.Index",
              },
            },
          },
          c2: {
            type: "void",
            "x-component": "ArrayTable.Column",
            "x-component-props": {
              title: "起止年月",
              align: "center",
            },
            properties: {
              startEndTime: {
                type: "string",
                "x-component": "Input.TextArea",
                required: true,
                "x-decorator": "FormItem",
                "x-component-props": {
                  placeholder:
                    "衔接时间为9月入学、7月毕业，如2017年9月至2020年7月",
                },
              },
            },
          },
          c3: {
            type: "void",
            "x-component": "ArrayTable.Column",
            "x-component-props": {
              title: "学校名称",
              align: "center",
            },
            properties: {
              schoolName: {
                type: "string",
                "x-component": "Input.TextArea",
                required: true,
                "x-decorator": "FormItem",
                "x-component-props": {
                  placeholder:
                    "学校全称（同一个阶段在不同学校就读的填写学籍所在学校或最后毕业的学校名称）",
                },
              },
            },
          },
          c4: {
            type: "void",
            "x-component": "ArrayTable.Column",
            "x-component-props": {
              width: 150,
              title: "证明人",
              align: "center",
            },
            properties: {
              certifier: {
                type: "string",
                "x-component": "Input.TextArea",
                required: true,
                "x-decorator": "FormItem",
                "x-component-props": {
                  placeholder:
                    "指班主任或学校其他老师，填姓名，不能单纯填成某老师",
                },
              },
            },
          },
          c5: {
            type: "void",
            "x-component": "ArrayTable.Column",
            "x-component-props": {
              title: "操作",
              width: 200,
            },
            properties: {
              item: {
                type: "void",
                "x-component": "FormItem",
                properties: {
                  remove: {
                    type: "void",
                    "x-component": "ArrayTable.Remove",
                  },
                  moveDown: {
                    type: "void",
                    "x-component": "ArrayTable.MoveDown",
                  },
                  moveUp: {
                    type: "void",
                    "x-component": "ArrayTable.MoveUp",
                  },
                },
              },
            },
          },
        },
      },
      properties: {
        add: {
          type: "void",
          "x-component": "ArrayTable.Addition",
          title: "添加条目",
        },
      },
    },
  };
}

/** 学生基础信息 */
export const baseInfoSchema: ISchema<Student> = {
  type: "object",
  properties: {
    layout: {
      type: "void",
      "x-component": "FormGrid",
      "x-component-props": {
        maxColumns: [1, 2, 3],
        columnGap: 40,
      },
      properties: modifySchema(StudentBase(), {
        studentIdCard: {
          "x-component-props": {
            disabled: true,
          },
        },
        studentName: {
          required: true,
        },
        studentNation: {
          required: true,
        },
        studentPolitical: {
          required: true,
        },
        sex: {
          required: true,
        },
        birthday: {
          required: true,
        },
        phonenumber: {
          required: true,
        },
        nativePlace: {
          required: true,
        },
        studentExamCode: {
          required: true,
        },
        // heath: {
        //   required: true,
        // },
        studentAddress: {
          required: true,
        },
        nowAddress: {
          required: true,
        },
        graduationType: {
          required: true,
        },
        disciplines: {
          required: true,
        },
        foreignLanguage: {
          required: true,
        },
        parentTel1: {
          required: true,
        },
        studentFrom: {
          required: true,
        },
        communistYouthLeague: {
          required: true,
        },
        partyChina: {
          required: true,
        },
        studentOrganization: {
          required: true,
        },
        rewardsPunishment: {
          required: true,
        },
        hobbies: {
          required: true,
        },
        dormitory: {
          required: true,
        },
        counsellor: {
          required: true,
        },
        counsellorTel: {
          required: true,
        },
        trainSection: {
          required: true,
        },
      }),
    },
  },
};

/** 学生学校信息 */
export const schoolInfoSchema: ISchema = {
  type: "object",
  properties: {
    layout: {
      type: "void",
      "x-component": "FormGrid",
      "x-component-props": {
        maxColumns: [1, 2, 3],
        columnGap: 40,
      },
      properties: modifySchema(StudentSchool(), {
        studentCode: {
          "x-disabled": true,
        },
        studentCollege: {
          "x-component-props": {
            clearable: true,
            filterable: true,
          },
          required: true,
        },
        studentGrade: {
          "x-component-props": {
            clearable: true,
            filterable: true,
          },
          "x-reactions": {
            dependencies: [".studentCollege#dataSource", ".studentCollege"],
            fulfill: {
              run: "querySchoolDictByPre($self, $deps[0], $deps[1])",
            },
          },
          required: true,
        },
        studentMajor: {
          "x-component-props": {
            clearable: true,
            filterable: true,
          },
          "x-reactions": {
            dependencies: [".studentGrade#dataSource", ".studentGrade"],
            fulfill: {
              run: "querySchoolDictByPre($self, $deps[0], $deps[1])",
            },
          },
          required: true,
        },
        studentClass: {
          "x-component-props": {
            clearable: true,
            filterable: true,
          },
          "x-reactions": {
            dependencies: [".studentMajor#dataSource", ".studentMajor"],
            fulfill: {
              run: "querySchoolDictByPre($self, $deps[0], $deps[1])",
            },
          },
          required: true,
        },
        admissionMethod: {
          required: true,
        },
        educationalYear: {
          required: true,
        },
      }),
    },
  },
};

/** 学生教育信息 */
export const scoreInfoSchema: ISchema = {
  type: "object",
  properties: {
    layout: {
      type: "void",
      "x-component": "FormGrid",
      "x-component-props": {
        maxColumns: [1, 2, 3],
        columnGap: 40,
      },
      properties: modifySchema(StudentScore(), {
        submissionScore: {
          required: true,
        },
        chinese: {
          required: true,
        },
        math: {
          required: true,
        },
        language: {
          required: true,
        },
        comprehensive: {
          required: true,
        },
        featureScore: {
          required: true,
        },
      }),
    },
  },
};

export const extraInfoSchema: ISchema = {
  type: "object",
  properties: {
    layout: {
      type: "void",
      "x-component": "FormGrid",
      "x-component-props": {
        maxColumns: [1, 2, 3],
        columnGap: 40,
      },
      properties: modifySchema(StudentExtraInfo(), {
        familyMembers: {
          "x-decorator-props": {
            gridSpan: "span 3",
          },
          minItems: 1,
          maxItems: 7,
          required: true,
        },
        educationalExperience: {
          "x-decorator-props": {
            gridSpan: "span 3",
          },
          minItems: 1,
          maxItems: 7,
          required: true,
        },
      }),
    },
  },
};
